package com.bookcloud.java21.chapter12.泛型接口125;

import java.util.List;

public class RepositoryExample {
  public static void main(String[] args) {
    Repository<User> userRepository = new UserRepository();
    userRepository.add(new User(1, "张三", 18));
    userRepository.add(new User(2, "李四", 19));
    userRepository.add(new User(3, "王五", 20));
    // 使用get取
    User user = userRepository.get(1);
    System.out.println(user);
    // 修改对象
    user.setAge(99);
    // 调用update方法修改对象
    userRepository.update(user.getId(), user);
    // 调用get方法获取修改后的对象
    User updatedUser = userRepository.get(user.getId());
    System.out.println(updatedUser);
    // 调用delete方法删除对象
    userRepository.delete(user.getId());
    // 获取所有用户
    List<User> userList = userRepository.getAll();
    System.out.println("=============== 内存的对象 ==========");
    for (User u : userList) {
      System.out.println(u);
    }
  }
}
